home *** CD-ROM | disk | FTP | other *** search
/ CD Exchange / CD Exchange - Volume 1.iso / utils / misc / bytefilter / source / bytefilter.s next >
Text File  |  1993-10-14  |  15KB  |  762 lines

  1. ;
  2. ; ByteFilter V1.20   05-Sep-1993
  3. ;
  4. ; (c) 1993 by Jan Hagqvist
  5. ;
  6.  
  7. ; V0.01  Friday,   03-Sep-1993        ; Open window etc.
  8. ; V0.30  Saturday, 04-Sep-1993        ; Filter, slow mode
  9. ; V1.00  -      "     "      -        ; Filter, fast mode
  10. ; V1.05  Sunday,   05-Sep-1993        ; Fixed a bug in fast&slow-filter
  11. ; V1.20  -      "     "      -        ; Filter, ultrafast mode
  12.  
  13.  
  14.     include "jhextras.i"
  15.  
  16.   XREF _LVOOpenLibrary
  17.   XREF _LVOCloseLibrary
  18.   XREF _LVOOpenWindow
  19.   XREF _LVOCloseWindow
  20.   XREF _LVOWaitPort
  21.   XREF _LVOGetMsg
  22.   XREF _LVOReplyMsg
  23.   XREF _LVOMove
  24.   XREF _LVOText
  25.   XREF _LVOActivateGadget
  26.   XREF _LVORefreshGList
  27.   XREF _LVORemoveGadget
  28.   XREF _LVOAddGadget
  29.   XREF _LVOSetAPen
  30.   XREF _LVOOpen
  31.   XREF _LVOClose
  32.   XREF _LVOSeek
  33.   XREF _LVORead
  34.   XREF _LVOWrite
  35.   XREF _LVOAllocMem
  36.   XREF _LVOFreeMem
  37.  
  38.  
  39. JAM1                equ 0
  40. WBENCHSCREEN            equ 1
  41. GFLG_GADGHCOMP            equ $0000
  42. GFLG_GADGHIMAGE            equ $0002
  43. GFLG_DISABLED            equ $0100
  44. GACT_RELVERIFY            equ $0001
  45. GACT_TOGGLESELECT        equ $0100
  46. GTYP_BOOLGADGET            equ $0001
  47. GTYP_STRGADGET            equ $0004
  48. IDCMP_GADGETUP            equ $00000040
  49. IDCMP_CLOSEWINDOW        equ $00000200
  50. WFLG_SMART_REFRESH        equ $00000000
  51. WFLG_DRAGBAR            equ $00000002
  52. WFLG_DEPTHGADGET        equ $00000004
  53. WFLG_CLOSEGADGET        equ $00000008
  54. WFLG_ACTIVATE            equ $00001000
  55. WFLG_RMBTRAP            equ $00010000
  56.  
  57.  
  58. ByteFilter
  59.   move.l  4,a6
  60.   moveq.l #0,d0
  61.   lea     JHExtrasName(pc),a1
  62.   jsr     _LVOOpenLibrary(a6)
  63.   move.l  d0,JHExtrasBase
  64.   tst.l   d0
  65.   beq     Quit
  66.  
  67.   move.l  JHExtrasBase(pc),a0
  68.   move.l  ml_DosLib(a0),DosBase
  69.   move.l  ml_GfxLib(a0),GfxBase
  70.   move.l  ml_IntuitionLib(a0),IntuitionBase
  71.   move.w  ml_SysVersion(a0),SysVersion
  72.  
  73.   bsr     CreateHexGadgets
  74.  
  75.   move.l  IntuitionBase(pc),a6
  76.   lea     NewWindow(pc),a0
  77.   jsr     _LVOOpenWindow(a6)
  78.   move.l  d0,MyWindow
  79.   move.l  d0,a0
  80.   move.l  50(a0),MyRastPort
  81.   move.l  86(a0),MyUserPort
  82.  
  83.   lea     SourceNameGadget(pc),a0
  84.   bsr     ActivateGadget
  85.  
  86.   move.l  GfxBase(pc),a6
  87.   move.l  MyRastPort(pc),a1
  88.   moveq.l #2,d0
  89.   jsr     _LVOSetAPen(a6)
  90.  
  91.   move.l  #GreetsString,StatusArgs
  92.   bsr     ShowStatusLine
  93.  
  94.  
  95. WaitForMessage
  96.   tst.b   QuitFlag
  97.   bne     Quit
  98.  
  99.   move.l  4,a6
  100.   move.l  MyUserPort(pc),a0
  101.   jsr     _LVOWaitPort(a6)
  102. WaitForMessage2
  103.   move.l  4,a6
  104.   move.l  MyUserPort(pc),a0
  105.   jsr     _LVOGetMsg(a6)
  106.   tst.l   d0
  107.   beq.s   WaitForMessage
  108.   move.l  d0,a1
  109.   move.l  20(a1),Class
  110.   move.w  24(a1),Code
  111.   move.w  26(a1),Qualifier
  112.   move.l  28(a1),IAddress
  113.   jsr     _LVOReplyMsg(a6)
  114.   cmp.l   #IDCMP_CLOSEWINDOW,Class
  115.   bne.s   WaitForMessage3
  116.   move.b  #1,QuitFlag
  117. WaitForMessage3
  118.   cmp.l   #IDCMP_GADGETUP,Class
  119.   bne.s   WaitForMessage4
  120.   move.l  IAddress(pc),a0
  121.   tst.l   40(a0)
  122.   beq.s   WaitForMessage4
  123.   move.l  IntuitionBase(pc),a6
  124.   move.l  40(a0),a0
  125.   jsr     (a0)
  126. WaitForMessage4
  127.   bra     WaitForMessage2
  128.  
  129.  
  130. Quit
  131.   move.l  IntuitionBase(pc),a6
  132.   tst.l   MyWindow
  133.   beq.s   Quit2
  134.   move.l  MyWindow(pc),a0
  135.   jsr     _LVOCloseWindow(a6)
  136. Quit2
  137.   move.l  4,a6
  138.   tst.l   JHExtrasBase
  139.   beq.s   Quit3
  140.   move.l  JHExtrasBase(pc),a1
  141.   jsr     _LVOCloseLibrary(a6)
  142. Quit3
  143.   moveq.l #0,d0
  144.   rts
  145.  
  146.  
  147. ShowStatusLine
  148.   move.l  GfxBase(pc),a6
  149.   move.l  MyRastPort(pc),a1
  150.   move.l  #374,d0
  151.   move.l  #185,d1
  152.   jsr     _LVOMove(a6)
  153.  
  154.   move.l  JHExtrasBase(pc),a6
  155.   lea     StatusFormat(pc),a0
  156.   lea     StatusArgs(pc),a1
  157.   lea     StatusString,a2
  158.   jsr     _LVOJHFormatAString(a6)
  159.  
  160.   lea     StatusString,a0
  161.   jsr     _LVOJHStrLen(a6)
  162.   move.l  GfxBase(pc),a6
  163.   move.l  MyRastPort(pc),a1
  164.   jsr     _LVOText(a6)
  165.   rts
  166.  
  167. Invert
  168.   move.l  #InvertString,StatusArgs
  169.   bsr     ShowStatusLine
  170.  
  171.   move.l  IntuitionBase(pc),a6
  172.   lea     HexFlags,a3
  173.   lea     HexGadgets,a4
  174.   lea     IntuiTexts,a5
  175.   move.l  #255,d3
  176. Invert2
  177.   bchg    #0,0(a3,d3.w)
  178.  
  179.   bchg    #7,13(a4)
  180.  
  181.   add.l   #44,a4
  182.   add.l   #44,a5
  183.   dbf     d3,Invert2
  184.  
  185.   lea     HexGadgets,a0
  186.   move.l  MyWindow(pc),a1
  187.   sub.l   a2,a2
  188.   moveq.l #-1,d0
  189.   jsr     _LVORefreshGList(a6)
  190.  
  191.   move.l  #WaitingString,StatusArgs
  192.   bsr     ShowStatusLine
  193.   rts
  194.  
  195.  
  196. CheckHexFlag
  197.   lea     HexFlags,a3
  198.   move.l  IAddress,a4
  199.  
  200.   move.w  38(a4),d3            ; Byte number
  201.   bchg    #0,0(a3,d3.w)            ; Change byte state
  202.  
  203.   move.l  #WaitingString,StatusArgs
  204.   bsr     ShowStatusLine
  205.   rts
  206.  
  207. SourceName
  208.   lea     DestNameGadget(pc),a0
  209.   bsr     ActivateGadget
  210.  
  211.   move.l  #WaitingString,StatusArgs
  212.   bsr     ShowStatusLine
  213.   rts
  214.  
  215. DestName
  216.   lea     SourceNameGadget(pc),a0
  217.   bsr     ActivateGadget
  218.  
  219.   move.l  #WaitingString,StatusArgs
  220.   bsr     ShowStatusLine
  221.   rts
  222.  
  223.  
  224. Filter
  225.   move.l  DosBase(pc),a6
  226.   move.l  #SourceFileName,d1
  227.   move.l  #1005,d2
  228.   jsr     _LVOOpen(a6)
  229.   move.l  d0,d6                ; d6=sourcefile pointer
  230.   tst.l   d0
  231.   beq     NoSource
  232.  
  233.   move.l  JHExtrasBase(pc),a6
  234.   move.l  #DestFileName,d1
  235.   move.l  #1006,d2
  236.   move.l  MyWindow(pc),a0
  237.   jsr     _LVOJHOpen(a6)
  238.   move.l  d0,d7                ; d7=destfile pointer
  239.   tst.l   d0
  240.   beq     NoDest
  241.  
  242.   move.l  DosBase(pc),a6
  243.   move.l  d6,d1
  244.   moveq.l #0,d2
  245.   moveq.l #1,d3
  246.   jsr     _LVOSeek(a6)            ; Bounce to the end of the sourcefile
  247.   move.l  d6,d1
  248.   moveq.l #0,d2
  249.   moveq.l #-1,d3
  250.   jsr     _LVOSeek(a6)            ; And back to the beginning
  251.   move.l  d0,FileSize
  252.  
  253.   move.l  4,a6
  254.   move.l  FileSize(pc),d0
  255.   moveq.l #0,d1
  256.   jsr     _LVOAllocMem(a6)        ; Get mem for sourcefile
  257.   move.l  d0,SourceMem
  258.   tst.l   d0                ; Did we get the mem?
  259.   bne.s   GetMem            ; Yes
  260.   bsr     FilterSlow            ; No, do it slow
  261.   bra.s   GetMem2
  262. GetMem
  263.   move.l  4,a6
  264.   move.l  FileSize(pc),d0
  265.   moveq.l #0,d1
  266.   jsr     _LVOAllocMem(a6)        ; Get mem for sourcefile
  267.   move.l  d0,DestMem
  268.   tst.l   d0                ; Did we get the mem?
  269.   beq.s   GetMem1            ; No
  270.   bsr     FilterUltraFast        ; Do it ultrafast
  271.   bra.s   GetMem2
  272. GetMem1
  273.   bsr     FilterFast            ; Do it fast
  274. GetMem2
  275.   move.l  d0,d5                ; Store error flag
  276.   tst.l   DestMem
  277.   beq.s   GetMem3
  278.   move.l  4,a6
  279.   move.l  DestMem(pc),a1
  280.   move.l  FileSize(pc),d0
  281.   jsr     _LVOFreeMem(a6)        ; Free the mem
  282. GetMem3
  283.   tst.l   SourceMem
  284.   beq.s   GetMem4
  285.   move.l  4,a6
  286.   move.l  SourceMem(pc),a1
  287.   move.l  FileSize(pc),d0
  288.   jsr     _LVOFreeMem(a6)        ; Free the mem
  289. GetMem4
  290.  
  291.   move.l  DosBase(pc),a6
  292.   move.l  d7,d1
  293.   jsr     _LVOClose(a6)            ; Close destfile
  294.   move.l  d6,d1
  295.   jsr     _LVOClose(a6)            ; Close sourcefile
  296.  
  297.   cmp.l   #-1,d5            ; Was there a write error?
  298.   beq.s   FilterWriteError
  299.   move.l  #WaitingString,StatusArgs
  300.   bsr     ShowStatusLine
  301.   rts
  302. FilterWriteError
  303.   move.l  #WriteErrorString,StatusArgs
  304.   bsr     ShowStatusLine
  305.   rts
  306.  
  307. NoSource
  308.   move.l  #NoSourceString,StatusArgs
  309.   bsr     ShowStatusLine
  310.   rts
  311.  
  312. NoDest
  313.   move.l  DosBase(pc),a6
  314.   move.l  d6,d1
  315.   jsr     _LVOClose(a6)
  316.   move.l  #NoDestString,StatusArgs
  317.   bsr     ShowStatusLine
  318.   rts
  319.  
  320. FilterUltraFast
  321.   move.l  #FilteringUltraFastString,StatusArgs
  322.   bsr     ShowStatusLine
  323.   move.l  DosBase(pc),a6
  324.   move.l  d6,d1
  325.   move.l  SourceMem(pc),d2
  326.   move.l  FileSize(pc),d3
  327.   jsr     _LVORead(a6)            ; Read the source file
  328.   cmp.l   #-1,d0
  329.   beq.s   FilterUltraFast2
  330.  
  331.   move.l  FileSize(pc),d4
  332.   move.l  SourceMem(pc),a4
  333.   lea     HexFlags,a5
  334.   move.l  DestMem,a3
  335.   moveq.l #0,d5
  336. FilterUltraFast3
  337.   move.b  (a4)+,d0
  338.   ext.w   d0
  339.   and.w   #$00FF,d0
  340.   tst.b   0(a5,d0.w)
  341.   bne.s   FilterUltraFast3.1
  342.  
  343.   move.b  d0,(a3)+            ; Store it to the buffer
  344.   addq.l  #1,d5                ; Increase destfile length
  345. FilterUltraFast3.1
  346.   subq.l  #1,d4
  347.   tst.l   d4
  348.   bne.s   FilterUltraFast3
  349.  
  350.   move.l  d7,d1
  351.   move.l  DestMem(pc),d2
  352.   move.l  d5,d3
  353.   jsr     _LVOWrite(a6)            ; Write the destfile
  354. FilterUltraFast2
  355.   rts
  356.  
  357. FilterFast
  358.   move.l  #FilteringFastString,StatusArgs
  359.   bsr     ShowStatusLine
  360.   move.l  DosBase(pc),a6
  361.   move.l  d6,d1
  362.   move.l  SourceMem(pc),d2
  363.   move.l  FileSize(pc),d3
  364.   jsr     _LVORead(a6)            ; Read the source file
  365.   cmp.l   #-1,d0
  366.   beq.s   FilterFast2
  367.  
  368.   move.l  FileSize(pc),d4
  369.   move.l  SourceMem(pc),a4
  370.   lea     HexFlags,a5
  371.   lea     StatusString,a3
  372.   moveq.l #0,d5
  373. FilterFast3
  374.   move.b  (a4)+,d0
  375.   ext.w   d0
  376.   and.w   #$00FF,d0
  377.   tst.b   0(a5,d0.w)
  378.   bne.s   FilterFast3.1
  379.  
  380.   move.b  d0,(a3)+            ; Store it to the buffer
  381.   addq.l  #1,d5
  382.   cmp.w   #256,d5            ; Buffer full?
  383.   bne.s   FilterFast3.1            ; No
  384.  
  385.   move.l  d7,d1
  386.   move.l  #StatusString,d2
  387.   move.l  d5,d3
  388.   jsr     _LVOWrite(a6)            ; Write buffer
  389.   cmp.l   #-1,d0            ; Error?
  390.   beq.s   FilterFast2            ; Yes
  391.   lea     StatusString,a3
  392.   moveq.l #0,d5
  393. FilterFast3.1
  394.   subq